<?php
/**
 * Core_Data_Getdatabasedata
 * get data from database
 *
 * @author Adrian Stolarski
 */
class Core_Data_Getdatabasedata implements Core_Data_Sessiondatacheckoutable, Core_Data_Databasedatacomparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $session_model
     * session model handler
     * 
     */
    public $session_model;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * get_data()
     * get session data
     * 
     * @param array $variables
     * @return type $user_id
     */
    public function session_data_checkout(array $variables = null) {
        $user_id = $this->compare_data($variables);
        return $user_id;
    }
    
    /**
     * compare_data()
     * select user id from database
     * @param array $variables
     * @return type $user_data['id']
     */
    public function compare_data(array $variables = null) {
        $this->database->connect();
        $variables['user_name'] = $this->database->escape($variables['user_name']);
        $variables['user_password'] = $this->database->escape($variables['user_password']);
        $this->database->prepare(
                "SELECT * FROM users_data WHERE users_data.user_name="
                .$variables['user_name'].
                " AND users_data.user_password="
                .md5($variables['user_password']).
                ";"
                );
        $this->database->query();
        $user_data = $this->database->fetch('array');
        return $user_data['id'];
    }

}
